home *** CD-ROM | disk | FTP | other *** search
- Path: newshost.lanl.gov!tanmoy
- From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
- Newsgroups: comp.lang.c
- Subject: Re: Function Pointers
- Date: 06 Mar 1996 20:12:41 GMT
- Organization: Los Alamos National Laboratory
- Distribution: world
- Message-ID: <TANMOY.96Mar6131241@qcd.lanl.gov>
- References: <8BC3202.028600318C.uuout@mwcs.mb.ca>
- NNTP-Posting-Host: qcd.lanl.gov
- Mime-Version: 1.0
- Content-Type: text
- In-reply-to: bryan.schwartz@mwcs.mb.ca's message of Wed, 06 Mar 96 08:34:00 -0600
-
- In article <8BC3202.028600318C.uuout@mwcs.mb.ca>
- bryan.schwartz@mwcs.mb.ca (BRYAN SCHWARTZ) writes:
-
- <snip>
- BS: unsigned far x_get( void far *SX); function prototype
-
- This is a syntax error: C has no keyword called far.
-
- <snip>
- BS: typedef struct vid stuct to define screen
- BS: {
- <snip>
- BS: unsigned( far * s_get)(SX) ; function pointer in struct
-
- This is a syntax error, far is not a keyword in C.
-
- BS: } STRU
- BS:
- BS: int main(void)
- BS: {
- BS: STRU *k ; near pointer to struct
- BS: k->s_get = ( int near *)x_get ; PROBLEM here! ????
-
- This is a syntax error, near is not a key word in C.
-
- Without the near, it is non portable: there is no guarantee that a
- function pointer can be converted to int*.
-
- It is a constraint violation: an int* cannot be assigned to a function
- pointer without cast.
-
- Try, k->sget = x_get;, or with a redundant cast, k->s_get =
- (unsigned (*) (void*)) x_get.
-
- BS: return 0;
- BS: }
- BS: /* get a char + attribute from the screen using x_get() */
- BS: unsigned far x_get( SX ptr )
- BS: { /* SX ptr = address in screen buffer */
- BS: return( ptr->ja );
- BS: /* return char + attrib. to union */
- BS: }
- BS: Shoot holes in this code, Please! And tell me about it. I'm just
- BS: starting learning C. How do I store a function's address in a structure
- BS: successfully?
-
- If you are learning C, learn on a compiler that does C. Otherwise, you
- are deluding yourself thinking what you learn is the topic of this
- group.
-
- If you want to know more about near/far, ask in the appropriate
- newsgroup (one dealing with the platform you are on).
-
- Cheers
- Tanmoy
- --
- tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
- Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
- Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
- <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
- internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
- fax: 1 (505) 665 3003 voice: 1 (505) 665 4733 [ Home: 1 (505) 662 5596 ]
-